import 'package:flutter/material.dart';
import 'package:qaun_ni_dev/im/pages/conversation_list_page.dart';
import 'package:provider/provider.dart';
import 'package:qaun_ni_dev/pages/auditModule/auditModule.dart';
import 'package:qaun_ni_dev/pages/person/person.dart';
import 'package:qaun_ni_dev/pages/temp_reserve/other.dart';
import 'package:qaun_ni_dev/provider/rongImProvider.dart';
import 'package:flutter_custom_bottom_tab_bar/eachtab.dart';

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _HomePageState();
  }
}

class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
  TabController _tabController;
  var titles = ['审核', '客服','其它','我的'];
  int _selectedIndex = 0;

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, initialIndex: 0, length: titles.length);
    _tabController.addListener(() {
      setState(() => _selectedIndex = _tabController.index);
    });
    initPlatformState();
  }

  initPlatformState()  {
    Provider.of<RongImProvider>(context,listen: false).initImStateConnect(context);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Container(
          height: 60,
          child: Consumer<RongImProvider>(
            builder: (context,data,_) {
              int msgNoReadNumber = data.msgNoReadCount;
              String showNmuber = '';
              if(msgNoReadNumber <= 0) {
                showNmuber = '';
              } else if(msgNoReadNumber > 99){
                showNmuber = '99+';
              } else{
                showNmuber = msgNoReadNumber.toString();
              }
              return Column(
                children: <Widget>[
                  Divider(height: 2,),
                  TabBar(
                    isScrollable: false,
                    controller: _tabController,
                    indicatorColor: Colors.transparent,
                    labelColor: Colors.red,
                    labelPadding: EdgeInsets.all(0),
                    unselectedLabelColor: Colors.grey,
                    tabs: <Widget>[
                      EachTab(
                          width: 70,
                          height: 50,
                          padding: EdgeInsets.all(0),
                          icon: Icon(Icons.view_module),
                          text: titles[0],
                          iconPadding: EdgeInsets.fromLTRB(0, 0, 0, 2),
                          textStyle: TextStyle(fontSize: 10)
                      ),
                      EachTab(
                          width: 70, // 设置宽度，才好设置消息的偏移值
                          height: 50,
                          badgeNo: showNmuber,
                          badgeColor: Colors.red,
                          padding: EdgeInsets.all(0),
                          icon: Icon(Icons.contact_phone),
                          text: titles[1],
                          iconPadding: EdgeInsets.fromLTRB(0, 0, 0, 2),
                          textStyle: TextStyle(fontSize: 10)
                      ),
                      EachTab(
                          width: 70,
                          height: 50,
                          padding: EdgeInsets.all(0),
                          icon: Icon(Icons.border_all),
                          text: titles[2],
                          iconPadding: EdgeInsets.fromLTRB(0, 0, 0, 2),
                          textStyle: TextStyle(fontSize: 10)
                      ),
                      EachTab(
                          width: 70,
                          height: 50,
                          padding: EdgeInsets.all(0),
                          icon: Icon(Icons.person),
                          text: titles[3],
                          iconPadding: EdgeInsets.fromLTRB(0, 0, 0, 2),
                          textStyle: TextStyle(fontSize: 10)
                      ),
                    ],
                  )
                ],
              );
            },
          )

      ),
      body: TabBarView(
        physics: NeverScrollableScrollPhysics(), // 禁止左右滑动切换页面
        controller: _tabController,
        children: <Widget>[
          AuditModule(),
          ConversationListPage(),
          OtherPage(),
          Person(),
        ],
      ),
    );
  }
  
}



